<template>
    <basic-container>
        <div class="card-border">
            <card-header :header-data="headerData"></card-header>
            <avue-crud :data="myProjectData"
                       :option="option"
                       :page="page"
                       :table-loading="tableLoading"
                       @size-change="sizeChange"
                       @current-change="currentChange"
                       @search-change="searchChange"
                       @search-reset="searchReset"
                       class="avuecrud">
                <!--<template slot-scope="scope" slot="menu">-->
                <!--<div class="menu-title" @click.stop="regDetail(scope.row,scope.index)">-->
                <!--<i class="iconfont iconview" style="color: #409EFF;"></i>-->
                <!--<p class="menu-title-text">详情</p>-->
                <!--</div>-->
                <!--</template>-->
            </avue-crud>
        </div>
    </basic-container>
</template>
<script>
    import {PROJECT_DIC} from '@/const/dict'
    import { myProject } from "@/api/planning/project";
    export default {
        name: "myProject",
        created(){
            this.getMyProjectList(this.page)
            window.regDetail = this.regDetail;
        },
        data() {
            return {
                headerData:{
                    title:'我的办件'
                },
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 10 // 每页显示多少条
                },
                tableLoading:false,
                myProjectData: [],
                option: {
                    page: true,
                    addBtn: false,
                    editBtn: false,
                    addRowBtn: false,
                    indexLabel: "序号",
                    index: true,
                    cellBtn: false,
                    indexWidth:70,
                    delBtn: false,
                    columnBtn: false,
                    menu:false,
                    menuWidth: 100,
                    refreshBtn: false,
                    filterBtn: false,
                    searchBtn:false,
                    keyId: "id",
                    column: [
                        {
                            label: "规划名称",
                            prop: "title",
                            cell: true,
                            formatter: function (row, value, label, column) {
                                let a = '<a style="cursor: pointer;" onclick="regDetail(\'' + row.registerinfoId;
                                if (row.processId != null) {
                                    a += '\',\'' + row.processId;
                                }
                                a += '\')">' + value + '</a>';
                                return a;
                            }
                        },
                        {
                            label: "规划名称",
                            prop: "titleLike",
                            cell: true,
                            search:true,
                            hide: true,
                        },
                        {
                            label: "申报(牵头)单位",
                            prop: "orgName",
                            width:130,
                            cell: true
                        },
                        {
                            label: "规划类型",
                            prop: "category",
                            type: "select",
                            width:120,
                            search:true,
                            dicData: PROJECT_DIC.CATEGORY,
                            cell: true
                        },
                        {
                            label: "联系人姓名",
                            prop: "contactName",
                            width:120,
                            cell: true
                        },
                        {
                            label: "联系人电话",
                            prop: "contactNumber",
                            width:120,
                            cell: true
                        },
                    ]
                },
                categorysSearch:'',
                titleLikeSearch:'',
            };
        },
        methods: {
            getMyProjectList(page, params){
                this.tableLoading = true;
                myProject(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                },{categorys:'A,B,C,D'},params)).then(response => {
                    this.myProjectData = response.data.data.records;
                    this.page.total = response.data.data.total;
                    this.tableLoading = false
                })
            },
            searchReset(){
                this.categorysSearch = '';
                this.titleLikeSearch = '';
                let params = {
                    categorys:this.categorysSearch,
                    titleLike:this.titleLikeSearch,
                };
                this.getMyProjectList(this.page,params)
            },
            //搜索回调
            searchChange(params){
                this.page.currentPage = 1;
                this.getMyProjectList(this.page,this.dealSearchParam(params))
            },

            // 处理搜索过滤
            dealSearchParam(params){
                if(params.titleLike){
                    params.titleLike = params.titleLike;
                }
                if(params.category){
                    params.categorys = params.category
                }
                this.categorysSearch = params.category;
                this.titleLikeSearch = params.titleLike;
                return params;
            },
            currentChange(currentPage) {
                let page = this.page;
                page.currentPage = currentPage;
                let params = {
                    categorys:this.categorysSearch,
                    titleLike:this.titleLikeSearch,
                };
                this.getMyProjectList(page,params);
            },
            sizeChange(pageSize) {
                let page = this.page;
                page.pageSize = pageSize;
                let params = {
                    categorys:this.categorysSearch,
                    titleLike:this.titleLikeSearch,
                };
                this.getMyProjectList(page,params);
            },
            // 规划登记详情跳转
            regDetail(registerinfoId, processId) {
                let src = `/tagReply/detail/${registerinfoId}`;
                this.$router.push({
                    path: src,
                    query: {processId: processId}
                });
            },
        }
    };
</script>

<style lang="scss" scoped>
    .card-border {
        padding: 10px;
        border: 1px solid #d2d2d2;
    }
    .card-body {
        padding: 10px;
    }
    .head-button .el-button {
        padding: 8px 15px;
    }

</style>

